package com.gpframework.module.controller.module;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.constant.Constants;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.common.enums.PhoneMsgTypeEnum;
import com.gpframework.common.utils.poi.ExcelUtil;
import com.gpframework.module.common.service.ICommonPhoneMsgTemplateService;
import com.gpframework.module.module.domain.BrandAuditRecord;
import com.gpframework.module.module.domain.req.BrandAuditRecordAdd;
import com.gpframework.module.module.domain.req.BrandAuditRecordReq;
import com.gpframework.module.module.domain.req.BrandAuditRecordUpdate;
import com.gpframework.module.module.domain.req.BrandSendSmsReq;
import com.gpframework.module.module.domain.vo.BrandAuditRecordVo;
import com.gpframework.module.module.service.IBrandAuditRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName BrandAuditRecordController
 * @Author gpframework
 * @Date 2022-03-23
 * @Version 1.0.0
 * @Description 品牌审核Controller
 */
@Validated
@Api(tags = "品牌审核")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes", "unchecked"})
@RequestMapping("/module/brandAuditRecord")
public class BrandAuditRecordController extends BaseController {

    private final IBrandAuditRecordService iBrandAuditRecordService;
    private final ICommonPhoneMsgTemplateService iCommonPhoneMsgTemplateService;

    /**
     * @Description 分页
     * @Author gpframework
     * @Date 2022-03-23
     * @Param brandAuditRecord
     * @Return TableDataInfo
     */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('module:brandAuditRecord:list')")
    @GetMapping("/list")
    public TableDataInfo<BrandAuditRecordVo> list(BrandAuditRecordReq brandAuditRecordReq) {
        startPage();
        QueryWrapper<BrandAuditRecord> lqw = new QueryWrapper<BrandAuditRecord>();
        brandAuditRecordReq.generatorQuery(lqw, true);
        List<BrandAuditRecordVo> list = iBrandAuditRecordService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2022-03-23
     * @Param brandAuditRecord
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('module:brandAuditRecord:add')")
    @Log(title = "添加品牌审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody BrandAuditRecordAdd brandAuditRecordAdd) {
        BrandAuditRecord brandAuditRecord = Convert.convert(new TypeReference<BrandAuditRecord>() {
        }, brandAuditRecordAdd);
        return toAjax(iBrandAuditRecordService.save(brandAuditRecord) ? 1 : 0);
    }

    /**
     * @Description 审核
     * @Author gpframework
     * @Date 2022-03-23
     * @Param brandAuditRecord
     * @Return TableDataInfo
     */
    @ApiOperation("审核")
    @PreAuthorize("@ss.hasPermi('module:brandAuditRecord:edit')")
    @Log(title = "修改品牌审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody BrandAuditRecordUpdate brandAuditRecordUpdate) {
        if (StringUtils.isEmpty(brandAuditRecordUpdate.getBrandId()) || StringUtils.isEmpty(brandAuditRecordUpdate.getStatus())) {
            return AjaxResult.parameterError();
        }
        BrandAuditRecord brandAuditRecord = Convert.convert(new TypeReference<BrandAuditRecord>() {
        }, brandAuditRecordUpdate);
        return toAjax(iBrandAuditRecordService.edit(brandAuditRecord) ? 1 : 0);
    }




    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2022-03-23
     * @Param brandAuditRecord
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('module:brandAuditRecord:export')")
    @Log(title = "导出品牌审核", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BrandAuditRecordReq brandAuditRecordReq) {
        QueryWrapper<BrandAuditRecord> lqw = new QueryWrapper<BrandAuditRecord>();
        brandAuditRecordReq.generatorQuery(lqw, true);
        List<BrandAuditRecordVo> list = iBrandAuditRecordService.listVo(lqw);
        ExcelUtil<BrandAuditRecordVo> util = new ExcelUtil<BrandAuditRecordVo>(BrandAuditRecordVo.class);
        return util.exportExcel(list, "brandAuditRecord");
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2022-03-23
     * @Param brandAuditRecord
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('module:brandAuditRecord:query')")
    @GetMapping(value = "/{auditRecordId}")
    public AjaxResult<BrandAuditRecordVo> getInfo(@PathVariable("auditRecordId") Long auditRecordId) {
        return AjaxResult.success(iBrandAuditRecordService.getVoById(auditRecordId));
    }


    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2022-03-23
     * @Param brandAuditRecord
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('module:brandAuditRecord:remove')")
    @Log(title = "删除品牌审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{auditRecordIds}")
    public AjaxResult remove(@PathVariable Long[] auditRecordIds) {
        return toAjax(iBrandAuditRecordService.removeByIds(Arrays.asList(auditRecordIds)) ? 1 : 0);
    }
}
